/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.com.apresentacao.pedagogico;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import src.com.negocio.pedagogico.CadastrarIdioma;
import src.com.negocio.pedagogico.CadastrarNivelIdioma;
import src.com.negocio.pedagogico.ConsultarAluno;
//import src.com.negocio.pedagogico.ConsultarTurma;

/**
 *
 * @author Patricia   
 */
public class ConsultaAluno extends javax.swing.JFrame {

    /**
     * Creates new form Consultaaluno
     */
    public ConsultaAluno() throws SQLException {
        initComponents();
        //idioma.setEnabled(false);

        CadastrarIdioma c = new CadastrarIdioma();

        for (int i = 0; i < c.consultaIdioma().size(); i++) {
            idioma.addItem(c.consultaIdioma().get(i));
        }

        CadastrarNivelIdioma n = new CadastrarNivelIdioma();

        for (int i = 0; i < n.consultaNivel().size(); i++) {
            nvCurso.addItem(n.consultaNivel().get(i));
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jInternalFrame2 = new javax.swing.JInternalFrame();
        iidioma = new javax.swing.JLabel();
        pesquisar = new javax.swing.JButton();
        idioma = new javax.swing.JComboBox();
        nome = new javax.swing.JLabel();
        nomeCompleto = new javax.swing.JTextField();
        nivCurso = new javax.swing.JLabel();
        nvCurso = new javax.swing.JComboBox();
        codTur = new javax.swing.JLabel();
        cdTurma = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        retornoAluno = new javax.swing.JTable();
        jRadioButton1 = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jInternalFrame2.setTitle("Consulta - Aluno");
        jInternalFrame2.setToolTipText("");
        jInternalFrame2.setVisible(true);

        iidioma.setText("Idioma:");
        iidioma.setToolTipText("");
        iidioma.setEnabled(false);

        pesquisar.setText("Pesquisar");
        pesquisar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pesquisarMouseClicked(evt);
            }
        });

        idioma.setEnabled(false);

        nome.setText("Nome:");
        nome.setToolTipText("");

        nomeCompleto.setToolTipText("");

        nivCurso.setText("Nível de curso:");
        nivCurso.setToolTipText("");
        nivCurso.setEnabled(false);

        nvCurso.setEnabled(false);

        codTur.setText("Código da turma:");
        codTur.setToolTipText("");
        codTur.setEnabled(false);

        cdTurma.setToolTipText("");
        cdTurma.setEnabled(false);

        retornoAluno.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null}
            },
            new String [] {
                "Aluno", "Idioma", "Nivel de curso", "Codigo da turma"
            }
        ));
        retornoAluno.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                retornoAlunoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(retornoAluno);

        jRadioButton1.setSelected(true);
        jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButton1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jInternalFrame2Layout = new javax.swing.GroupLayout(jInternalFrame2.getContentPane());
        jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout);
        jInternalFrame2Layout.setHorizontalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nivCurso)
                            .addComponent(codTur))
                        .addGap(18, 18, 18)
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                .addComponent(cdTurma, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(56, 56, 56)
                                .addComponent(pesquisar))
                            .addComponent(nvCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(iidioma)
                            .addComponent(nome))
                        .addGap(65, 65, 65)
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(idioma, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                .addComponent(nomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jRadioButton1)))))
                .addContainerGap())
        );
        jInternalFrame2Layout.setVerticalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nome)
                    .addComponent(nomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButton1))
                .addGap(19, 19, 19)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(iidioma)
                    .addComponent(idioma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nivCurso)
                    .addComponent(nvCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(codTur)
                            .addComponent(cdTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void pesquisarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pesquisarMouseClicked
        // TODO add your handling code here:
        String nome = nomeCompleto.getText().toString();
        String i_idioma = idioma.getSelectedItem().toString();
        String c_cdTurma = cdTurma.getText().toString();
        String n_nvCurso = nvCurso.getSelectedItem().toString();

        ConsultarAluno A = new ConsultarAluno();

        try {
            // ArrayList<String> result_aluno = A.consultaAluno(nome, i_idioma, c_cdTurma, n_nvCurso);
            ArrayList<String> result_aluno2 = A.consultaAluno2(nome);
            System.out.println("RESULT_ALUNO = " + result_aluno2);

            if (jRadioButton1.isSelected()) {
                if (!result_aluno2.isEmpty()) {
                    retornoAluno.setModel(new javax.swing.table.DefaultTableModel(new String[]{"Aluno", "Idioma", "Nivel de curso", "Codigo da turma"}, result_aluno2.size() / 4));
                    int i = 0;
                    for (int j = 0; j < result_aluno2.size() / 4; j++) {
                        for (int z = 0; z < 4; z++) {
                            retornoAluno.setValueAt(result_aluno2.get(i), j, z);
                            i++; //System.out.print(result_turma.get(i));
                        }
                    }
                } else {
                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);
                    javax.swing.JOptionPane.showMessageDialog(inf, "O aluno informado não existe!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);

                }
            } else {
                ArrayList<String> result_aluno = A.consultaAluno(i_idioma, c_cdTurma, n_nvCurso);

                if (!result_aluno.isEmpty()) {
                    retornoAluno.setModel(new javax.swing.table.DefaultTableModel(new String[]{"Aluno", "Idioma", "Nivel de curso", "Codigo da turma"}, result_aluno.size() / 4));
                    int i = 0;
                    for (int j = 0; j < result_aluno.size() / 4; j++) {
                        for (int z = 0; z < 4; z++) {
                            retornoAluno.setValueAt(result_aluno.get(i), j, z);
                            i++; //System.out.print(result_turma.get(i));
                        }
                    }
                } else {
                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);
                    javax.swing.JOptionPane.showMessageDialog(inf, "O aluno informado não existe!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);

                }

            }




        } catch (SQLException ex) {
            Logger.getLogger(ConsultaAluno.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_pesquisarMouseClicked

    private void jRadioButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton1MouseClicked
        if (!jRadioButton1.isSelected()) {
            nome.setEnabled(false);
            nomeCompleto.setEnabled(false);
            nivCurso.setEnabled(true);
            idioma.setEnabled(true);
            nvCurso.setEnabled(true);
            iidioma.setEnabled(true);
            codTur.setEnabled(true);
            cdTurma.setEnabled(true);
        } else {
            nome.setEnabled(true);
            nomeCompleto.setEnabled(true);
            nivCurso.setEnabled(false);
            idioma.setEnabled(false);
            nvCurso.setEnabled(false);
            iidioma.setEnabled(false);
            codTur.setEnabled(false);
            cdTurma.setEnabled(false);
        }
    }//GEN-LAST:event_jRadioButton1MouseClicked

    private void retornoAlunoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_retornoAlunoMouseClicked
        try {
            String aluno = retornoAluno.getValueAt(retornoAluno.getSelectedRow(), 0).toString();
            CadastroAluno n = new CadastroAluno();
            n.setAluno(aluno);
            n.initValue();
            n.setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(ConsultaTurma.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_retornoAlunoMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ConsultaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ConsultaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ConsultaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ConsultaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new ConsultaAluno().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(ConsultaAluno.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cdTurma;
    private javax.swing.JLabel codTur;
    private javax.swing.JComboBox idioma;
    private javax.swing.JLabel iidioma;
    private javax.swing.JInternalFrame jInternalFrame2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel nivCurso;
    private javax.swing.JLabel nome;
    private javax.swing.JTextField nomeCompleto;
    private javax.swing.JComboBox nvCurso;
    private javax.swing.JButton pesquisar;
    private javax.swing.JTable retornoAluno;
    // End of variables declaration//GEN-END:variables
}
